<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="cn.eports.learn.domain.User" %>
<%@ page isELIgnored="false" %>
<%@ page import="java.util.*" %>

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>EL表达式</title>
	</head>
	<body>
	    <h3>EL表达式的语法</h3>
		${3 > 4} <br/>
		\${3 > 4}
		<hr style="background-color:blue;height:1px;">

		<h3>算数运算符</h3>
		${3 + 4} <br>
		${3 / 4} <br>
		${3 div 4} <br>
		${3 % 4} <br>
		${3 mod 4} <br>
		<hr style="background-color:blue;height:1px;">

		<h3>比较运算符</h3>
		${3 == 4}<br>
        <hr style="background-color:blue;height:1px;">

		<h3>逻辑运算符</h3>
		${3 > 4  && 3 < 4} <br>
		${3 > 4  and 3 < 4} <br>
        <hr style="background-color:blue;height:1px;">

		<h4>empty运算符</h4>
		<%
		    String str = "";
		    request.setAttribute("str",str);
		    List list = new ArrayList();
		    request.setAttribute("list",list);
		%>
		${not empty str} <br>
		${not empty list} <br>
		<hr style="background-color:blue;height:1px;">

        <h3>el从域中获取值</h3>
		<%
            // 在域中存储数据
			session.setAttribute("name","李四");
			request.setAttribute("name","张三");
			session.setAttribute("age","23");
			request.setAttribute("str","");
		%>

		${requestScope.name} <br>
		${sessionScope.age} <br>
		${sessionScope.haha} <br>
		${name} <br>
		${sessionScope.name} <br>
		<hr style="background-color:blue;height:1px;">

        <h3>el获取对象中的值</h3>
		<%
			User user = new User();
			user.setName("张三");
			user.setAge(23);
			// user.setBirthday(new Date());
	        user.setGender("男");
	        user.setAddress("河北");
	        user.setQq("123456789");
	        user.setEmail("111@qq.com");
			request.setAttribute("u",user);
			List list2 = new ArrayList();
			list2.add("aaa");
			list2.add("bbb");
			list2.add(user);
			request.setAttribute("list2",list2);
			Map map = new HashMap();
			map.put("sname","李四");
			map.put("gender","男");
			map.put("user",user);
			request.setAttribute("map",map);
		%>

        ${requestScope.u} <br>

		<%--
		    * 通过的是对象的属性来获取
		        * setter或getter方法，去掉set或get，在将剩余部分，首字母变为小写。
		        * setName --> Name --> name
		--%>

		${requestScope.u.name} <br>
		<%-- 只要对象的名称是单独唯一的，就可以忽略域名，直接用对象名来查找--%>
		${u.age} <br>
		${u.gender} <br>
	    ${u.qq} <br>
		${u.address} <br>
        <hr style="background-color:blue;height:1px;">

		<h3>el获取List值</h3>
		${list2} <br>
		${list2[0]} <br>
		${list2[1]} <br>
		${list2[10]} <br>

		${list2[2].name}
		<hr style="background-color:blue;height:1px;">

		<h3>el获取Map值</h3>
		${map.gender} <br>
		${map["gender"]} <br>
		${map.user.name} <br>
        <hr style="background-color:blue;height:1px;">

		<h4>获取request隐式对象</h4>
		${pageContext.request}<br>
		<hr style="background-color:blue;height:1px;">

		<h4>在jsp页面动态获取虚拟目录</h4>
		${pageContext.request.contextPath}
		<hr style="background-color:blue;height:1px;">

	</body>
</html>